import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../layout' //布局页

Vue.use(VueRouter)
//解决重复点击左侧菜单的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    meta: {
      title: "首页",
      icon: 'el-icon-s-home',
    },
    name: 'index',
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/home.vue'),
        meta: {
          title: "首页",
        }
      },
    ]
  },
  {
    path: '/banner',
    component: Layout,
    meta: {
      title: "轮播管理",
      icon: 'el-icon-s-home',
    },
    name: 'banner',
    children: [
      {
        path: 'list',
        name: 'bannerList',
        component: () => import('@/views/banner/index.vue'),
        meta: {
          title: "轮播管理",
        }
      },
    ]
  },
  {
    path: '/product',
    component: Layout,
    meta: {
      title: "产品管理",
      icon: 'el-icon-s-home',
    },
    name: 'product',
    children: [
      {
        path: 'category',
        name: 'productCategoryList',
        component: () => import('@/views/category/index.vue'),
        meta: {
          title: "产品分类",
        }
      },
      {
        path: "product",
        name: "product",
        component: () => import("@/views/product/index"),
        meta: { title: "产品管理" }
      },
      {
        path: "application",
        name: "productApplication",
        component: () => import("@/views/product/application/index"),
        meta: { title: "产品申请记录" }
      },
    ]
  },
  {
    path: '/member',
    component: Layout,
    meta: {
      title: "会员管理",
      icon: 'el-icon-s-home',
    },
    name: 'member',
    children: [
      {
        path: 'list',
        name: 'memberList',
        component: () => import('@/views/member/index.vue'),
        meta: {
          title: "会员管理",
        }
      },
    ]
  },
  {
    path: '/system',
    component: Layout,
    meta: {
      title: "系统管理",
      icon: 'el-icon-s-custom',
    },
    name: 'system',
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/system/user/index.vue'),
        meta: {
          title: "用户管理",
        }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/system/role/index.vue'),
        meta: {
          title: "角色管理",
        }
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/system/menu/index.vue'),
        meta: {
          title: "菜单管理",
        }
      },
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/login'),
    meta: {
      title: "欢迎登录",
    },
    hidden: true //导航菜单忽略选项
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: asyncRoutes
})

export default router
